home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 199_01 / gedio.asm < prev    next >
Assembly Source File  |  1987-12-15  |  29KB  |  1,016 lines

  1. ;------------------------------------------------------------------
  2. ; Gedio.asm: Screen and keyboard interface routines for the PC
  3. ;
  4. ; For GED WordStar-like screen editor
  5. ; DeSmet C implementation by Mel Tearle - 08/06/86
  6. ;
  7. ; Microsoft Macroassembler implementation by Michael Yokoyama - 12/06/86
  8. ; Revised by Mel Tearle - 07/25/87
  9. ;
  10. ; data starts here
  11. ;------------------------------------------------------------------
  12.  
  13. _data segment word public 'data'
  14. const segment word public 'const'
  15. const ends
  16.  
  17. _bss segment word public 'bss'
  18. _bss ends
  19.  
  20.  dgroup group const,_bss,_data
  21.  assume cs: _text, ds: dgroup, ss: dgroup, es: dgroup
  22.  
  23. ; In this implementation, all special and function keys are translated
  24. ; to the following values.
  25. ; control key translations
  26.  
  27.  
  28. ; control key translations - mapped into cursor-pad.
  29.  
  30. up_char         equ   5     ;arrow up
  31. down_char       equ  24     ;arrow down
  32. left_char       equ  19     ;arrow left
  33. right_char      equ   4     ;arrow right
  34. bol_char        equ  15     ;Home
  35. eol_char        equ  16     ;End
  36. pageup_char     equ  18     ;PgUp
  37. pagedown_char   equ   3     ;PgDn
  38. Del_char        equ   7     ;Del
  39.  
  40. ; function key definitions
  41.  
  42. M1      equ 128
  43. M2      equ 129
  44. M3      equ 130
  45. M4      equ 145
  46. M5      equ 132
  47. M6      equ 133
  48. M7      equ 134
  49. M8      equ 135
  50. M9      equ 136
  51. M10     equ 137
  52.  
  53. ; special keys - toggles and keypress
  54.  
  55. Insert_key      equ 138
  56. Caps_Lock_on    equ 139
  57. Caps_Lock_off   equ 140
  58. Alt_key         equ 146
  59.  
  60. grey_minus      equ 142
  61. grey_plus       equ 143
  62.  
  63.  
  64. ; the table that is used to make the translation
  65. ; note - not all used
  66.  
  67. convert db  72,  up_char
  68.         db  80,  down_char
  69.         db  75,  left_char
  70.         db  77,  right_char
  71.         db  71,  bol_char
  72.         db  79,  eol_char
  73.         db  73,  pageup_char
  74.         db  81,  pagedown_char
  75. ;       db  78,  grey_plus
  76. ;       db  74,  grey_minus
  77.         db  82,  Insert_key
  78.         db  83,  Del_char
  79.  
  80.         db  59, M1
  81.         db  60, M2
  82.         db  61, M3
  83.         db  62, M4
  84.         db  63, M5
  85.         db  64, M6
  86.         db  65, M7
  87.         db  66, M8
  88.         db  67, M9
  89.         db  68, M10
  90.         db   0, 255     ;illegal character
  91.  
  92.  
  93. ; equates for bios interface.
  94. ; the interrupt and codes for the screen interface interrupt.
  95.  
  96. video       equ 10h     ;interrupt for dealing with screen
  97.  
  98. mode        equ 0       ;code for setting new screen mode
  99. curtype     equ 1       ;code for setting new cursor type
  100. setcur      equ 2       ;code for addressing cursor
  101. readcur     equ 3       ;code for reading cursor location
  102. readlp      equ 4       ;code for reading light pen position
  103. setpage     equ 5       ;code to select active page
  104. scrollup    equ 6       ;code to scroll screen up
  105. scrolldn    equ 7       ;code to scroll screen nown
  106. readch      equ 8       ;code to read a character from screen
  107. writeach    equ 9       ;code to write char and attributes
  108. writech     equ 10      ;code to write character only
  109. setpal      equ 11      ;code to set new setpal or border
  110. wdot        equ 12      ;code to write a dot
  111. rdot        equ 13      ;code to read a dot
  112. wtty        equ 14      ;code to write as if teletype
  113. state       equ 15      ;code to find current screen status
  114.  
  115. ; used in set_video
  116.  
  117. mono_adr     equ  0b000h   ;mono adapter
  118. graph_adr    equ  0b800h   ;graphics adapter*
  119.  
  120. vadrs        dw  0
  121.  
  122. ; the interrupt and codes for the keyboard interface.
  123.  
  124. keyboard     equ 16h     ;interrupt 16 to deal with keyboard
  125.  
  126. cicode       equ 0       ;code for reading a character
  127. cstscode     equ 1       ;reports if character is ready
  128. kbstatus     equ 2       ;get keyboard status - shifts, caplocks
  129.  
  130. kbset        db  0
  131.  
  132. ; caution: must change column number if 40 column mode
  133.  
  134. crt_cols     equ 80
  135.  
  136. ; Note: 25 for MS-DOS, 24 for CP/M as cp/m steals the bottom line.
  137.  
  138. _scr_rows dw 24           ; current number of rows, for ged, was 25
  139. _scr_cols dw crt_cols     ; current number of columns
  140. _scr_mode db 0            ; current screen mode
  141. _scr_page db 0            ; current page
  142. _scr_attr db 7            ; current attributes for screen
  143.                           ; 7 is white letters on black
  144. _scr_window_top db 1      ; first line to scroll, was 0
  145.  
  146. _data ends
  147.  
  148. ;------------------------------------------------------------------
  149. ;  code starts here
  150. ;------------------------------------------------------------------
  151.  
  152.  _text segment byte public 'code'
  153.  assume cs:_text
  154.  
  155. ; Variables available to C programs
  156.  
  157.  public _scr_cols,    _scr_rows,     _scr_xy,      _scr_clr
  158.  public _scr_mode,    _scr_page,     _scr_attr,    _scr_window_top
  159.  public _scr_setup,   _scr_term,     _scr_csts,    _scr_setmode
  160.  public _scr_clrl,    _scr_cls,      _scr_scup,    _scr_scrup
  161.  public _scr_scrdn,   _scr_co,       _scr_ci,      _get_graphic
  162.  public _scr_sinp,    _scr_cursoff,  _scr_curson,  _scr_mark
  163.  public _scr_putch,   _scr_delete,   _get_mode,    _calc_video
  164.  public _scr_putstr,  _scr_aputch,   _get_kbstat,  _caps_on
  165.  public _scr_scdn,    _scr_aputs,    _set_video
  166.  
  167.  
  168. ;-------------------------------------------------------------------------
  169. ;  _scr_setup   Call _scr_setup before using any other routine unless the
  170. ;               starting mode is 80X25 character mode (3,4, or 7).
  171. ;               This routine must be called for monochrome (mode 7)
  172. ;               for _scr_curson to set a proper cursor.
  173. ;
  174. ;  Usage: mode = _scr_setup();
  175. ;-------------------------------------------------------------------------
  176.  
  177. _scr_setup proc near
  178.     push  bp
  179.     mov   bp, sp
  180.  
  181.     mov   ah,state           ; get current state
  182.     int   video
  183.     mov   _scr_mode, al      ; current mode
  184.     mov   cl,ah              ; make cols a word
  185.     mov   ch,0
  186.     mov   _scr_cols, cx      ; 40 or 80 columns
  187.     mov   _scr_page, bh
  188.     mov   _scr_attr, 7       ; set to white chars on black
  189.     cmp   al, 4              ; see if a character mode
  190.     jc    got_attr
  191.     cmp   al, 7              ; 7 is for graphics mode
  192.     jz    got_attr
  193.     mov   _scr_attr, 0       ; attribute is zero in graphics
  194. got_attr:
  195.     mov   ah,0               ; return int containing mode
  196.     push  ax                 ; slight detour
  197.     call  _set_video         ; get display address
  198.     pop   ax
  199.  
  200.     pop   bp
  201.     ret
  202. _scr_setup endp
  203.  
  204.  
  205. ;-------------------------------------------------------
  206. ; _scr_term   Do any required termination.
  207. ;
  208. ;  Usage:     _scr_term();
  209. ;-------------------------------------------------------
  210.  
  211. _scr_term proc near
  212.     ret
  213. _scr_term endp
  214.  
  215.  
  216. ;-------------------------------------------------------
  217. ;  _scr_setmode    Set a new screen mode.
  218. ;  Usage:          _scr_setmode(new mode);
  219. ;-------------------------------------------------------
  220.  
  221. _scr_setmode proc near
  222.     push  bp
  223.     mov   bp, sp
  224.  
  225.     mov   al, [bp+4]  ; new mode value
  226.     mov   ah, mode
  227.     int   video       ; set new mode
  228.     call  _scr_setup  ; remember new values
  229.  
  230.     pop   bp
  231.     ret
  232. _scr_setmode endp
  233.  
  234.  
  235. ;-------------------------------------------------------
  236. ;  _scr_xy   Sets cursor at any location.
  237. ;
  238. ;  Usage:    _scr_xy( col, row );
  239. ;-------------------------------------------------------
  240.  
  241. _scr_xy  proc near
  242.     push  bp
  243.     mov   bp, sp
  244.  
  245.     mov   dx, [bp+4]          ; col
  246.     mov   ax, [bp+6]          ; row
  247.     mov   dh, al
  248.     mov   bh, _scr_page       ; force page zero
  249.     mov   ah, setcur          ; set cursor location
  250.     int   video               ; call BIOS
  251.  
  252.     pop   bp
  253.     ret
  254. _scr_xy endp
  255.  
  256.  
  257. ;-------------------------------------------------------
  258. ;  _scr_clr   Clear entire screen
  259. ;
  260. ;  Usage:     _scr_clr();
  261. ;-------------------------------------------------------
  262.  
  263. _scr_clr proc near
  264.     push  bp
  265.     mov   bp, sp
  266.  
  267.     mov   al, 0              ; ask for a clear window
  268.     xor   cx, cx             ; start at 0,0
  269.     mov   dh, byte ptr _scr_rows     ;last line
  270.     dec   dh
  271.     mov   dl, byte ptr _scr_cols     ;clear entire width
  272.     dec   dl                 ; last column is width-1
  273.     mov   bh, _scr_attr      ; attributes for new bl